//
//  BaseViewController.m
//  DreamOf
//
//  Created by 薛小刚 on 2018/3/27.
//  Copyright © 2018年 薛小刚. All rights reserved.
//

#import "BaseViewController.h"
#import <KMCGeigerCounter/KMCGeigerCounter.h>


@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [KMCGeigerCounter sharedGeigerCounter].enabled = YES;

    WeakSelf(weSelf, self);
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    self.view.backgroundColor = [UIColor color_main_background_color];
    self.dataArray = [NSMutableArray array];
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
    
    /// 添加左侧按钮
    [self setLeftImageBarButtonItemWithFrame:CGRectZero image:@"B_back" selectImage:@"" action:^(GUIButton *button) {
        [weSelf leftNavigationAction];
    }];
}

- (void) leftNavigationAction {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)setTitle:(NSString *)title {
    [self setTextTitleViewWithFrame:CGRectMake(0, 0, 80, 20) title:title fontSize:getLargeFont() textColor:[UIColor color_text_white]];
}

- (void) setTitle:(NSString *)title color:(UIColor *) color {
    [self setTextTitleViewWithFrame:CGRectMake(0, 0, 80, 20) title:title fontSize:getLargeFont() textColor:color];
}

- (void) pushNextViewController:(UIViewController *) controller {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.navigationController pushViewController:controller animated:YES];
    });

}
- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setNavigationBarBackgroundWithImage:[UIImage getImageWithColor:[UIColor color_content_background_color] alp:1]];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void) alertViewWithTitle:(NSString *) title message:(NSString *) message buttonsTitles:(NSArray *) arrays action:(void(^)(NSInteger index)) actionBlock {
    UIAlertController * controller = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
    for (int i = 0; i < arrays.count; i++) {
        UIAlertAction * action;
        if (i == arrays.count - 1) {
            action = [UIAlertAction actionWithTitle:arrays[i] style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                actionBlock(i);
            }];
        } else {
            action = [UIAlertAction actionWithTitle:arrays[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                actionBlock(i);
            }];
        }
        
        [controller addAction:action];
    }
    [self presentViewController:controller animated:YES completion:nil];
}

- (void) alertViewCenterWithTitle:(NSString *) title message:(NSString *) message buttonsTitles:(NSArray *) arrays action:(void(^)(NSInteger index)) actionBlock {
    UIAlertController * controller = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    for (int i = 0; i < arrays.count; i++) {
        UIAlertAction * action;
        if (i == arrays.count - 1) {
            action = [UIAlertAction actionWithTitle:arrays[i] style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                actionBlock(i);
            }];
        } else {
            action = [UIAlertAction actionWithTitle:arrays[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                actionBlock(i);
            }];
        }
        
        [controller addAction:action];
    }
    [self presentViewController:controller animated:YES completion:nil];
}

@end
